import koa from 'koa';
import router from '#Routes/route.js';
import api from '#Routes/api.js';
import KoaLogger from 'koa-logger';
import appConifg from '#Config/app.js';

import { dataGet } from '#Utils/helper.js';
import bodyParser from 'koa-bodyparser';

import { Log } from '#Libs/logs/logger.js'

const app = new koa();

app.keys = [appConifg.app_key];

app.use(KoaLogger());

app.use(bodyParser());

app.use(router.routes()).use(router.allowedMethods());

app.use(api.routes()).use(api.allowedMethods());

const port = dataGet(appConifg, 'app_port', 3000), host = dataGet(appConifg, 'app_url', 'localhost');


app.listen(port, host, () => {
    console.log(`Server is running on ${host}:${port}`);
})

app.on('error', (err, ctx) => {
    Log.error('server error', err, ctx)
});